"""
核验相关Pydantic模式
创建时间：2025-09-12
作者：开发团队
目的：定义核验相关的数据验证和序列化模式
"""

from pydantic import BaseModel, Field
from datetime import datetime


class QrCodeVerificationRequest(BaseModel):
    """二维码核验请求模式"""
    qr_data: str = Field(..., description="二维码数据")
    guard_id: int = Field(..., description="门卫ID")


class VisitorInfo(BaseModel):
    """访客信息模式"""
    name: str = Field(..., description="访客姓名")
    phone: str = Field(..., description="访客手机号")
    id_card: str | None = Field(None, description="访客身份证号")
    company: str | None = Field(None, description="访客公司")
    visit_time: str = Field(..., description="访问时间")
    purpose: str = Field(..., description="访问事由")
    host_name: str = Field(..., description="被访人姓名")
    host_phone: str = Field(..., description="被访人电话")
    expires_at: str = Field(..., description="二维码过期时间")
    is_special: bool = Field(False, description="是否特殊访客")
    special_type: str | None = Field(None, description="特殊访客类型")


class QrCodeVerificationResponse(BaseModel):
    """二维码核验响应模式"""
    result: str = Field(..., description="核验结果 (valid/invalid/expired)")
    visitor_info: VisitorInfo | None = Field(None, description="访客信息")
    message: str | None = Field(None, description="错误信息")


class VerificationSubmitRequest(BaseModel):
    """核验结果提交请求模式"""
    qr_data: str = Field(..., description="二维码数据")
    guard_id: int = Field(..., description="门卫ID")
    result: str = Field(..., pattern="^(pass|reject)$", description="核验结果")
    notes: str | None = Field(None, description="备注信息")


class VerificationRecordResponse(BaseModel):
    """核验记录响应模式"""
    id: int
    visitor_name: str
    visitor_phone: str
    host_name: str
    verification_time: datetime
    result: str
    is_special: bool
    special_type: str | None = None

    class Config:
        orm_mode = True


class VerificationRecordDetailResponse(VerificationRecordResponse):
    """核验记录详情响应模式"""
    visitor_id_card: str | None = None
    visitor_company: str | None = None
    host_phone: str
    visit_time: datetime
    purpose: str
    guard_id: int
    rejection_reason: str | None = None
    notes: str | None = None
    created_at: datetime


class VerificationRecordsResponse(BaseModel):
    """核验记录列表响应模式"""
    records: list[VerificationRecordResponse]
    total: int
    skip: int
    limit: int